<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
  <div region="center" style="padding:0px;border:0px">
  <t:datagrid name="tmblWorktimeParentList" singleSelect="true" checkbox="true" fitColumns="false" title="排班总览表" actionUrl="tmblWorktimeParentController.do?datagrid" idField="id" fit="true" queryMode="group">
   <t:dgCol title="ID"  field="id"  hidden="true"  queryMode="group"  width="120"></t:dgCol>
   <t:dgCol title="班次名称"  field="arrangework"    width="120"></t:dgCol>
   <t:dgCol title="创建人"  field="createname"    query="true"  width="120"></t:dgCol>
   <t:dgCol title="人" hidden="true" field="createUserName"   width="120"></t:dgCol>
   
   
<!--    借来传输数据，不是用来查询 -->
   <t:dgCol title="流入时间" hidden="true" field="day"  query="true"></t:dgCol>
			
   <t:dgCol title="操作" field="opt" width="500">
   		<%-- <t:dgFunOpt title="录入排班表"  funname="openWorkTable(id)"/> --%>
   		<t:dgFunOpt title="编辑排班表"  funname="updateWorkTable(id,createUserName,createUserName)"/>
   		<t:dgFunOpt title="查看排班表"  funname="showWorkTableMyself(id,createUserName)"/>
   		<t:dgFunOpt title="查看排班总表"  funname="showWorkTable(id)"/>
   		<t:dgFunOpt title="查看明细表"  funname="showWorkTableList(id)"/>
   		<t:dgFunOpt title="删除排班表"  funname="dele(id)"/>
   </t:dgCol>
   
   <t:dgToolBar title="录入" icon="icon-add" url="tmblWorktimeParentController.do?goAdd" funname="adds"></t:dgToolBar>
  <%--  <t:dgToolBar title="编辑" icon="icon-edit" url="tmblWorktimeParentController.do?goUpdate" funname="update"></t:dgToolBar> --%>
  </t:datagrid>
  </div>
 </div>
		
 <script type="text/javascript">
 $(document).ready(function(){
 		//给时间控件加上样式
 			$("input[name='day']").attr("class","Wdate").click(function(){WdatePicker({dateFmt:'yyyy-MM'});});
 			/*$("#tmblWorktimeParentListtb").find("input[name='createdate_end']").attr("class","Wdate").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
 			 $("#tmblWorktimeParentListtb").find("input[name='updatedate_begin']").attr("class","Wdate").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
 			$("#tmblWorktimeParentListtb").find("input[name='updatedate_end']").attr("class","Wdate").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});}); */
 }); 

 	/* function adds(){
			
	 opens("排班录入" , "tmblWorktimeParentController.do?goAdd","","","");//这个open方法是框架里面自带的
	} */
 	function adds(){
 		 $.dialog.setting.zIndex = getzIndex(true); 
 		$.dialog({content: 'url:tmblWorktimeParentController.do?goAdd', 
 				zIndex: 2100, title: '录入', lock: true, width: '400px', 
 				height: '500px', opacity: 0.4, 
 		button: [
 		   {name: '确定', callback:function(){
 			   var iframe = this.iframe.contentWindow;
 			    var rowsData = iframe.$('#selectPalce').datagrid('getSelections');
 			   var arrangework=iframe.$("#arrangework").val();
 			    var no=iframe.$("#no").val();
 			  if(arrangework==null || arrangework==""){
 				  alert('请选择排班时间！');
 				  
 			  }
 			  
 				 if (!rowsData || rowsData.length==0) {
 			        alert("请选择服务点！");
 			        
 				 }
 				 
 				if(rowsData.length>0 && arrangework!=null && arrangework!=""){
 				var ids='',names='';
 				if(rowsData.length>0){
 					  for(i=0;i<rowsData.length;i++){
 					     var node = rowsData[i];
 					     ids += node.id+',';
 					    names += node.workplace+',';
 					  }
 					 iframe.$("#wId").val(ids);
 					iframe.$("#wName").val(names);
 				}
 				
 				$.ajax({//检查是否有服务点重复
 					url: "<%=path%>/tmblWorktimeParentController.do?checkDepart",
 					type:"post",
 					dataType:"json",
 					data:{
 						arrangework:arrangework,
 						workPlaceId:ids
 					},
 					success: function(data){
 						if(data.success){
 							$.ajax({//异步保存
 								url: "<%=path%>/tmblWorktimeParentController.do?doAdd",
 			 					type:"post",
 			 					dataType:"json",
 			 					data:{
 			 						arrangework:arrangework,
 			 						workPlaceId:ids,
 			 						number:no,
 			 						wId:ids,
 			 						wName:names
 			 					},
 			 					success: function(datas){
 			 						if(datas.success){
 			 							window.location.reload();
 			 							updateWorkTable(datas.msg,'录入排班表','bb');
 			 						}else{
 			 							alert("保存失败，请联系管理员！");
 			 							return;
 			 						}
 			 					}
 							});
 							
 							return;
 						}else{
 							alert(data.msg);
 							adds();
 						}
 					}
 				});
 				
 				}else{
 					dialog("open");
 				}
 		   }, focus: true},
 		   {name: '取消', callback: function (){}}
 	   ]}).zindex();
 	}
		/* function opens(title,addurl,gname,width,height) {
			gridname=gname;
			var mess;
			var flag=false;
			var flag2=false;
			var info;
			width = 530;
			height = 430;
			if(width=="100%" || height=="100%"){//应该是设置弹出时的位置
				
				width = window.top.document.body.offsetWidth;
				height =window.top.document.body.offsetHeight-100;
			}
		    
			if(typeof(windowapi) == 'undefined'){
			
					info=$.dialog({
					id:'b',
					content: 'url:'+addurl,
					/* zIndex: getzIndex(),
					width:width,
					height:height,
					title:title,
					opacity : 0.3,
					cache:false,
					button: [//设置按钮
					         {
					             name: '确定',
					             callback: function () {
					            	 iframe = this.iframe.contentWindow;//指代弹出页面
					            	 $('#sub', iframe.document).click();
									return false;//false应该是框体不关闭，可是这里就是关闭
									 /* 这三句存在，才能被这个框架的form标签识别运行 */
					            /*  }
					         }
					     ],

					
				    cancelVal: '关闭',
				    cancel: true
				});
			}
		} */ 
 
 
 
 var pid=0;
function openWorkTable(id){
	pid=id;
	 $.dialog.setting.zIndex = getzIndex(true); 
		$.dialog({content: 'url:tmblWorktimeParentController.do?goSelectDepart', 
				zIndex: 2100, title: '服务点列表', lock: true, width: '400px', 
				height: '600px', opacity: 0.4, 
		button: [
		   {name: '确定', callback:function(){
			   var iframe = this.iframe.contentWindow;
			    var rowsData = iframe.$('#selectAppUser').datagrid('getSelections');
			    
		   		 if (!rowsData || rowsData.length==0) {
			        tip('<t:mutiLang langKey="common.please.select.edit.item"/>');
			        return;
		   		 }
		   		var ids='',names='';
		   		if(rowsData.length>0){
					  for(i=0;i<rowsData.length;i++){
					     var node = rowsData[i];
					     ids += node.id+',';
					    names += node.workplace+',';
					  }
				}
		   		
		   		$.ajax({
					url: "<%=path%>/tmblWorktimeParentController.do?checkDepart",
					type:"post",
					dataType:"json",
					data:{
						id:pid,
						workPlaceId:ids
					},
					success: function(data){
						if(data.success){
							addOneTab('<t:mutiLang langKey="排版表"/>' , "tmblWorktimeParentController.do?openWorkTable&id="+pid+"&workPlaceId="+ids);
						}else{
							alert(data.msg);
							return;
						}
					}
				});
			   
		   }, focus: true},
		   {name: '取消', callback: function (){}}
	   ]}).zindex();
 }

 function updateWorkTable(id,title,name){
	 if( title!='录入排班表'){
		 title='编辑排班表';
		 $.ajax({
				url: "<%=path%>/tmblWorktimeParentController.do?check",
				type:"post",
				dataType:"json",
				data:{
					id:id
				},
				success: function(data){
					if(data.success){
						 addOneTab(title, "tmblWorktimeParentController.do?updateWorkTable&id="+id+"&mess="+"update"+"&name="+name);
					}else{
						alert(data.msg);
						return;
					}
				}
			});
		
	 }else{
		 addOneTab(title, "tmblWorktimeParentController.do?updateWorkTable&id="+id+"&mess="+"update"+"&name="+name);
	 }
	 
 }	
 function showWorkTable(id){
	 addOneTab('<t:mutiLang langKey="查看排班总表"/>' , "tmblWorktimeParentController.do?updateWorkTable&id="+id+"&mess="+"show");
 }
 function showWorkTableMyself(id,name){
		 $.ajax({
				url: "<%=path%>/tmblWorktimeParentController.do?check",
				type:"post",
				dataType:"json",
				data:{
					id:id
				},
				success: function(data){
					if(data.success){
						addOneTab('<t:mutiLang langKey="查看排班表"/>' , "tmblWorktimeParentController.do?updateWorkTable&id="+id+"&mess="+"showMyself"+"&name="+name);
					}else{
						alert("只能查看自己的排班表！");
						return;
					}
				}
			});
		
	 
	 
 }
 
 function dele(id){
		 $.ajax({
				url: "<%=path%>/tmblWorktimeParentController.do?doDel",
				type:"post",
				dataType:"json",
				data:{
					id:id
				},
				success: function(data){
					if(data.success){
						alert("删除成功！");
						window.location.reload();
					}else{
						alert("删除失败！");
						return;
					}
				}
			});
	 
	 
}
 
 function showWorkTableList(id){
	 addOneTab('<t:mutiLang langKey="班次明细表"/>' , "tmblWorktimeController.do?lists&pid="+id);
 }
 </script>